﻿@model PagedList<Common.Background.WebDepartments>
@{
    ViewBag.Title = "Index";
}
<script type="text/javascript">
    function search() {
        location.href = "/Department/Index?deptname=" + $("#DeptName").val() + "&page=1";
    }
</script>
@Html.Partial("ContentListTag.Partial", new List<Common.Background.Models.LinkModel> { 
    new Common.Background.Models.LinkModel("部门列表列表展示", "/Department/Index?flag=0"), 
    new Common.Background.Models.LinkModel("部门列表树型展示", "/Department/Index?flag=1"),
})
@if (string.IsNullOrEmpty(Request.QueryString["flag"]) || Request.QueryString["flag"] == "0")
{
    <p>
        部门：<input type="text" name="DeptName" id="DeptName" value="@Request.QueryString["deptName"]" />&nbsp;&nbsp;<input
            type="button" id="search" value="查询" onclick="search()" />
    </p>
    <table>
        <tr>
            <th>编号
            </th>
            <th>部门名称
            </th>
            <th>上级部门
            </th>
            <th>排序
            </th>
            <th>员工数量
            </th>
        </tr>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @item.DepartmentID
                    </td>
                    <td>
                        @item.DepartmentName
                    </td>
                    <td>
                        @(item.WebDepartments2 == null ? "" : item.WebDepartments2.DepartmentName)
                    </td>
                    <td>
                        @item.SortNumber
                    </td>
                    <td>
                        @item.UserCount
                    </td>
                </tr>
            }
        </tbody>
        <tfoot>
            <tr>
                <td colspan="5">@EntityFrameworks.Web.Core.Helper.PagerHelper.Pager(Html, Model)
                </td>
            </tr>
        </tfoot>
    </table>
}
else
{
    @Html.GetDataTree(new BackgroundBase<WebDepartments>().GetModel(), "DepartmentID", -1, "Department")
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#DepartmentID_Tree").bind("loaded.jstree", function (e, data) {
            data.inst.open_all(-1); // -1默认全部展开节点 
        }).jstree({
            "plugins": ["themes", "html_data", "ui"],
            "core": { "initially_open": ["DepartmentID_node1"] }
        });
    });
</script>
